package utils

import "strings"

// FindStrBetweenStr 查找left和right字符串中间的字符串
func FindStrBetweenStr(s string, left, right string) string {
	i1 := strings.Index(s, left)
	if left == "" {
		i1 = 0
	}
	i2 := strings.Index(s, right)
	if right == "" {
		i2 = len(s)
	}
	if i1 < 0 || i2 < 0 {
		return ""
	}
	return s[i1+len(left) : i2]
}

// PadLeftString 左填充字符串至指定长度
func PadLeftString(str string, l int, pad string) string {
	if len(str) >= l {
		return str[0:l]
	}
	for {
		str = pad + str
		if len(str) >= l {
			return str[0:l]
		}
	}
}

// PadRightString 右填充字符串至指定长度
func PadRightString(str string, l int, pad string) string {
	if len(str) >= l {
		return str[0:l]
	}
	for {
		str += pad
		if len(str) >= l {
			return str[0:l]
		}
	}
}
